package com.example.aop;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static com.google.common.base.Predicates.or;

/**
 * @author 何星霖
 * @date 2018/10/15 16:29
 */
@Configuration
@EnableSwagger2//启用Swagger2
public class SwaggerConfig{
    //从配置文件中获取属性值
    final static String SERVICE_URL="http://localhost/";


    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                //.host("mlxcapi.12582.cn")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("test.demo")
                .description("手动集成swagger")
                .termsOfServiceUrl(SERVICE_URL)
                .version("1.0")
                .build();
    }

    //region cms接口
    private ApiInfo cmsApiInfo() {
        return new ApiInfoBuilder().title("Demo").description("后台管理系统")
                .termsOfServiceUrl(SERVICE_URL)
                .version("1.0").build();
    }

    @Bean(value = "cmsRestApi")
    public ApiSelectorBuilder cmsRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(cmsApiInfo()).groupName("controller").select()
                .apis(RequestHandlerSelectors.basePackage("com.example.controller"));
    }
    //endregion
}